using Microsoft.EntityFrameworkCore;
using MyTask.Domain.Models;
using MyTask.Infrastructure.Context;
using System;
using System.Threading.Tasks;
using Xunit;

namespace MyTask.Test
{
    public class TestDbContext
    {
        [Fact]
        public async Task Test1()
        {
            string connectionString = "Data Source=DESKTOP-MIB8DI4\\SQLEXPRESS;Initial Catalog=MyTask;Integrated Security=true;";
            var options = new DbContextOptionsBuilder<MyTaskContext>()
                .UseSqlServer(connectionString)
                .Options;

            Post post = new Post();
            post.Title = "Title1";
            post.Body = "Body1";
            using (var context = new MyTaskContext(options))
            {
                
                context.Posts.Add(post);
                context.SaveChanges();
            }

            using (var context = new MyTaskContext(options))
            {
                //Assert
                Assert.True(await context.Posts.AnyAsync(p => p.Id == post.Id));
            }
        }
    }
}
